# -*- coding: utf-8 -*-
from google.appengine.ext import db
from django.contrib.auth.models import User

class GuestBook(db.Model):
    content = db.StringProperty(required=True, multiline=True)
    #content = db.TextProperty(required=True)
    msgtype = db.StringProperty(
        required=True,
        choices=set(['Contact', 'Suggestion', 'Technical Problem', 'Bug Report']),
        default='Contact',
    )
    msgdate = db.DateTimeProperty(auto_now=False, auto_now_add=True)
    sender = db.ReferenceProperty(User, required=False, collection_name='guestbook_set')
    email = db.EmailProperty(required=False)

    @classmethod
    def create(cls, content, msgtype, sender=None, email=None):
        newmessage = GuestBook(content=content, msgtype=msgtype, sender=sender, email=email)
        newmessage.put()
        return newmessage
        
        
    @classmethod
    def get_all(cls):
        messages = cls.all()
        messages.order("-msgdate")
        return messages
